<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="../static/jquery-easyui-1.5.5.3/themes/bootstrap/easyui.css" />
<link rel="stylesheet" href="../static/jquery-easyui-1.5.5.3/themes/icon.css" />
<script src="../static/jquery-easyui-1.5.5.3/jquery.min.js"></script>
<script src="../static/jquery-easyui-1.5.5.3/jquery.easyui.min.js"></script>
<script src="../static/jquery-easyui-1.5.5.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
	$(function(){
		$("#beginDate").datebox({
			width: 200,
			editable: false,
			missingMessage:'开始日期必填'
		});
		$("#month").textbox({
			width: 200,
			missingMessage:'使用期限必填'
		});
		$("#cost").numberbox({
			width: 200,
			missingMessage:'缴纳费用必填'
		});
		
		
		$("#t_user").datagrid({
			idField: 'id',
			title: '授权列表',
			fitColumns: true,
			width: '100%',
			striped: true,
			rownumbers: true,
			url: 'list',
			frozenColumns: [
				[
					{
						field: 'ck',
						width: 50,
						checkbox: true
					}
				]
			],
			columns: [
				[
					{
						field: 'id',
						title: 'id',
						width: 100,
						align: 'center'
					},{
						field: 'beginDate',
						title: '开始日期',
						width: 100,
						align: 'center'
					},{
						field: 'month',
						title: '使用期限',
						width: 100,
						align: 'center'
					},{
						field: 'endDate',
						title: '结束日期',
						width: 100,
						align: 'center'
					},{
						field: 'Name',
						title: '租户名称',
						width: 100,
						align: 'center',
						formatter: function(value, rec){
							return rec.lessee.name;
						}
					},{
						field: 'Unit',
						title: '租户管理员',
						width: 100,
						align: 'center',
						formatter: function(value, rec){ 
							return rec.lessee.lesseeAdmin.unit;
						}
					},{
						field: 'cost',
						title: '缴纳费用',
						width: 100,
						align: 'center'
					}
				]
			],
			pagination: true,
			pageSize: 10,
			pageList: [3, 5, 10, 20],
			toolbar: [
				{
					text: '修改授权',
					iconCls: 'icon-edit',
					handler: function(){
						var arr = $('#t_user').datagrid('getSelections');
						if(arr.length != 1){
							$.messager.show({
								title: '提示信息',
								msg: '选中一行记录进行修改！'
							});
						}else{
							$('#mydialog').dialog('open');
							$('#myform input').val("");
							$('#myform').form('load', {  
								id:arr[0].id,
								beginDate:arr[0].beginDate,
								month:arr[0].month,
								cost:arr[0].cost,
								lessee:arr[0].lessee.id
							});
						}
					}
				}
			]
		});
		
		$("#btn1").click(function(){
			if($('#myform').form('validate')){
				$.ajax({
					type: 'post',
					url: 'save',
					cache: false,   
					data: $('#myform').serialize(),
					dataType: 'json',
					success: function(){
						$("#mydialog").dialog('close');
						$('#t_user').datagrid('reload');
						$.messager.show({
							title: '提示信息',
							msg: '操作成功！'
						});
					}
				});
			}else{
				$.messager.show({
					title: '提示信息',
					msg: '数据验证不通过，不能保存'
				});
			}
		});
		
		$("#btn2").click(function(){
			$("#mydialog").dialog('close');
		});
	});
</script>
</head>
<body>
	<div id="ss"> 
				<a href="../administrator/lessee_all" type="button">租户管理</a>
	</div>
	<table id = "t_user"></table>
	
	<div id = "mydialog" title="修改授权" modal="true"  draggable=false class="easyui-dialog" closed=true style="width:300px;">
		<form action="" method="post" id = "myform">
			<input type="hidden" name = "id" value="">
			<input type="hidden" name = "lessee" value="">
			<table>
				<tr>
					<td>开始日期：</td>
					<td><input type="text" name = "beginDate" id="beginDate" class="easyui-validatebox" required=true value="" ></td>
				</tr>
				<tr>
					<td>使用期限（月）：</td>
					<td><input type="text" name = "month" id="month" class="easyui-validatebox" required=true value="" ></td>
				</tr>
				<tr>
					<td>缴纳费用：</td>
					<td><input type="text" name = "cost" id="cost" class="easyui-validatebox" required=true missingMessage="缴纳费用不能为空" value="" ></td>
				</tr>
				<tr>
					<td colspan="2" align="center">
						<a id="btn1" class="easyui-linkbutton">确定</a>
						<a id="btn2" class="easyui-linkbutton">关闭</a>
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>